#include <iostream>
#include<string>
#include<ctemplate/template.h>

#include"oj_model.hpp"

using namespace std;

const string template_path="./template_html/";


namespace ns_view
{
    using namespace ns_model;
    class View
    {
    public:
        void AllExpandHtml(const vector<struct Question> &all,string* html)
        {
            //1.形成路径
            string src_html=template_path+"all_questions.html";
            //2.形成数字典
            ctemplate::TemplateDictionary root("all_questions");
            for(const auto& q:all)
            {
                ctemplate::TemplateDictionary* sub=root.AddSectionDictionary("question_list");
                sub->SetValue("number",q.number);
                sub->SetValue("title",q.title);
                sub->SetValue("star",q.star);
            }
            //3.获取被渲染的网页
            ctemplate::Template* tp1=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

            //4.开始完成渲染功能
            tp1->Expand(html,&root);

        }
        void OneExpandHtml(const struct Question& q,string* html)
        {
            string src_html=template_path+"one_question.html";
            ctemplate::TemplateDictionary root("one_questions");

            root.SetValue("number",q.number);
            root.SetValue("title",q.title);
            root.SetValue("star",q.star);
            root.SetValue("desc",q.desc);
            root.SetValue("pre_code",q.header);

            ctemplate::Template* tp1=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            
            tp1->Expand(html,&root);
        }
        View()
        {}
        ~View()
        {}
    private:
        
    };
}